package lei.e_java_math_number;

/**
 * @className: Java_math
 * @author: xl
 * @date: 2025/3/1 13:34
 * @Version: 1.0
 * @description:
 */

public class Java_Math {

    public static void main(String[] args) {

        System.out.println("Math.floor(" + 1.4 + ")=" + Math.floor(1.4));
        System.out.println("Math.round(" + 1.5 + ")=" + Math.round(1.6));
        System.out.println("Math.ceil(" + 1.6 + ")=" + Math.ceil(1.7));


        // 获取绝对值
        System.out.println(Math.abs(3.14)); // 3.14
        System.out.println(Math.abs(0)); // 0
        System.out.println(Math.abs(-2.5)); // 2.5
        System.out.println("================");

        // 向上取整
        System.out.println(Math.ceil(3.9)); // 4.0
        System.out.println(Math.ceil(3.1)); // 4.0
        System.out.println(Math.ceil(3.0)); // 3.0
        System.out.println("================");

        // 向下取整，抹零
        System.out.println(Math.floor(30.1)); // 30.0
        System.out.println(Math.floor(30.9)); // 30.0
        System.out.println(Math.floor(31.0)); // 31.0
        System.out.println("================");

        // 四舍五入
        System.out.println(Math.round(20.4)); // 20
        System.out.println(Math.round(10.5)); // 11
    }
}

